// components/rating/rating.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    count: {
      type: Number,
      value: 5,
    },
    selected: {
      type: Number,
      value: 0,
    },
    size: {
      type: String,
      value: '40',
    },
    defaultColor: {
      type: String,
      value: '#888888',
    },
    selectedColor: {
      type: String,
      value: '#f3d066',
    },
    icon: {
      type: String,
      value: 'star',
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentIndex: -1,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleSelect(event) {
      if (this.data.selected > 0) {
        return
      }
      const index = event.currentTarget.dataset.index
      this.setData({
        currentIndex: index,
      })
      const score = index + 1
      this.triggerEvent('rating', { rating: score })
    },
  },
})
